<template>
	<view style="background-color: azure;height: 100%;overflow: auto;">
		<view class="example">
			<form style="padding: 20rpx;">
				<view  style="display: flex;">
					<text style="line-height: 72rpx;">手机号码：</text>
					<view class="uni-form-item uni-column" style="width: 480rpx;">
						<input type="tel" class="uni-input" name="" v-model="addressData.phone" placeholder="请输入手机号" />
					</view>
				</view>
				<view style="display: flex;">
					<text style="line-height: 72rpx;">验证码：</text>
					<view class="uni-form-item uni-column column-with-btn">
						<input type="number" class="uni-input" name="" v-model="vc" placeholder="请输入验证码" style="width: 300rpx;"/>
						<button :class="{active : !disableCodeBtn}"  @click="getCode">{{codeBtn.text}}</button>
					</view>
				</view>
				<view  style="display: flex;">
					<text style="line-height: 72rpx;">新密码：</text>
					<view class="uni-form-item uni-column" style="width: 480rpx;">
						<input type="tel" class="uni-input" name="" v-model="psw" placeholder="请输入密码" />
					</view>
				</view>
			</form>
		</view>
		<view>
			<button type="primary" @click="updataphone" class="bind-buttom">提交</button>
		</view>
	</view>
</template>

<script>
	let App = getApp()
	export default {
		data() {
			return {
				show: false,
				state:false,
				userid:"",
				adminid:0,
				vc:'',
				codeBtn: {
					text: '获取验证码',
					waitingCode: false,
					count: this.seconds
				},
				addressData: {
					name: '',
					phone: '',
					address: '',
					moreAddres: '',
					idnum:"",
					bankscardnum:"",
					bankname:"",
					isdefult: 0
				},
				seconds: 120,
				timer:'',
				index:"",
				isShow: true,
				psw:''
			}
		},
		methods: {
			getCode: function () {
				
				let phone = this.addressData.phone
				var reg = /^1[3456789]\d{9}$/;
				if (phone == "") {
					uni.showToast({
						title: "手机号不能为空",
						icon: "none"
					})
				} else if (!reg.test(phone)) {
					uni.showToast({
						title: "请输入有效手机号",
						icon: "none"
					})
				} else {
					
					this.$api.interfaceApi('sendSms')({
						'mobile': phone,
						'admin_id':App.globalData.sys
					}).then(res=>{
						if(res.code == 201){
							uni.showToast({
								title:res.msg,
								icon:'none'
							})
						}
					})
			
					
					
					this.codeBtn.waitingCode = true;
					this.codeBtn.count = this.seconds;
					this.codeBtn.text = this.codeBtn.count + 's';
					
					let countdown = setInterval( () => {
						this.codeBtn.count--;
						this.codeBtn.text = this.codeBtn.count + 's';
						if( this.codeBtn.count < 0 ){
							clearInterval(countdown);
							this.codeBtn.text = '重新发送';
							this.codeBtn.waitingCode = false;
						}
					},1000);
				}	
			},
			
			//修改密码
			updataphone(){
				let userinfo = uni.getStorageSync('userinfo');
				uni.showLoading({
					title:"加载中"
				})
				this.$api.interfaceApi('updatepwd')({
					'id': userinfo,
					'phone': this.addressData.phone,
					'vc': this.vc,
					'password': this.psw
					//'sys':App.globalData.sys,
				}).then(res=>{
					if(res.code == 200){
						uni.showToast({
							title:res.msg,
							icon:'success'
						})
					}else{
						uni.showToast({
							title: res.msg,
							icon:'error'
						})
					}
					uni.hideLoading()
				})
			},
		},
		onLoad() {
			this.adminid=App.globalData.sys
			this.userid=uni.getStorageSync("user_id")
		}
	}
</script>

<style lang="scss" scoped>
	$color-primary: #1FD188;
	.uni-form-item{
		margin-bottom: 40upx;
		padding: 0;
		border-bottom: 1px solid #e3e3e3;
		.uni-input{
			font-size: 30upx;
			padding: 7px 0;
		}
	}
	
	.column-with-btn{
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
		button{
			font-size: 24upx;
			margin: 0;
			text-align: center;
			&:after{
				border: none
			}
			&.active{
				background-color: $color-primary;
				color: $uni-text-color-inverse;
			}
		}
	}
	
	.example {
			width: 690rpx;
			height: 350rpx;
			margin-top: 30rpx;
			margin-left: 30rpx;
			background-color: white;
			border-radius: 10px;
			display: flex;
	}
	
	.bind-buttom{
		width: 700rpx;
		height: 80rpx;
		margin-top: 20rpx;
		background-color: #49b9ff;
		border-radius: 40rpx;
	}
</style>